let express=require("express")()
let mysql=require("mysql")
let expressStatic=require("express-static")
let port=8080

let sql = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : '123456',
  database : 'chnyoo',
  timezone : "08:00"
});

sql.connect()

express.get("/getcontent",(request,response)=>{
	sql.query(`SELECT * FROM chnyoolist`,(error,data)=>{
		response.send(data)
	})
})
express.get("/getdetails",(request,response)=>{
	let id = request.query.id;
	console.log(id)
	sql.query(`SELECT * FROM chnyoolist WHERE id="${id}" `,(error,data)=>{
		if(error){
			console.log(error);
			response.send("error");
		}
		else{
			response.send(data[0])
			console.log(data)
		}
	})
})


express.get("/gettitle",(request,response)=>{
	let id = request.query.id;
	console.log(id)
	sql.query(`SELECT * FROM chnyoolist WHERE id="${id}" `,(error,data)=>{
		if(error){
			console.log(error);
			response.send("error");
		}
		else{
			response.send(data[0])
			console.log(data)
		}
	})
})





express.use(expressStatic(__dirname + '/static'))
express.listen(port)